home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BBS in a Box 7
/
BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso
/
Files
/
Prog
/
Q-R
/
QB Graphics.sea
/
dragger.bas
< prev
next >
Wrap
BASIC Source File
|
1991-04-21
|
7KB
|
200 lines
'------------------------------------------------------------------------------
' TITLE: dragger
' DATE: March 25, 1991
' AUTHOR: R. Gonzalez
'
' DESCRIPTION: Demonstrates alternative representations for an icon: sequence of
' QB primitives, "Picture" segment, or bitmap. The icon may be "dragged" using
' the XOR drawing mode.
'
' COMPILING: Remove STATIC declarations, uncomment indicated lines
' Check: Include MBPCs & MBLCs, Include runtime code, Make all arrays static,
' Use default window & menu, (if available: Generate 68020 & 68881 code).
'
' (MODIFICATION HISTORY)
' DATE:
' AUTHOR:
' DESCRIPTION:
'------------------------------------------------------------------------------
DEF FNdistance%(x1%,y1%,x2%,y2%) = SQR((x1%-x2%)*(x1%-x2%)+(y1%-y2%)*(y1%-y2%))
DIM SHARED points%,radius%,TRUE%,FALSE%,ast$,ast%(1000),pi
'MAIN
DIM method$,menu.item%,mouse.event%,a.x%,a.y%,rect%(4)
TRUE% = -1
FALSE% = 0
pi = 3.14159
radius% = 20 'ast%() is only big enough for about radius=60 (?)
points% = 10
initialize method$
CLS
a.x% = 100
a.y% = 100
PENMODE 10 'this helps overlapped areas of initial asterix be erased correctly
asterix a.x%,a.y%
PENMODE 8 'reset mode to COPY
setrect rect%(0),100,150,200,200
textbox "Presently using the "+method$+" method",rect%(0),0
'event loop (File and Edit menus handled automatically by QB)
WHILE TRUE%
IF MENU(0) = 3 THEN
menu.item% = MENU(1)
handle.method.menu menu.item%,method$
forecolor 30
asterix a.x%,a.y% 'erase asterix in case text overlaps it
forecolor 33
textbox "Presently using the "+method$+" method",rect%(0),0
PENMODE 10
asterix a.x%,a.y% 'restore asterix in case text overlaps it
PENMODE 8
END IF
IF MOUSE(0) = -1 THEN
handle.mouse.down method$,a.x%,a.y%
END IF
WEND
END
'------------------------------------------------------------------------------
' initialize menu and icon representations
' Note when the "showlevel" is 0 or less, the pen is hidden. HIDEPEN decrements
' the "showlevel" and SHOWPEN increments it.
'------------------------------------------------------------------------------
SUB initialize (method$) STATIC
method$ = "Primitives"
draw.menu method$
SHOWPEN 'pen must be on so GET will work. This makes "showlevel"=2
PICTURE ON 'note this issues a HIDEPEN, which reduces "showlevel" to 1
PENMODE 10 'change pen mode to XOR for Segment method
asterix radius%,radius%
PENMODE 8
PICTURE OFF 'this issues a SHOWPEN, increasing "showlevel" to 2
HIDEPEN 'reduce "showlevel" to 1 again.
ast$ = PICTURE$
GET (0,0)-(radius%*2,radius%*2),ast%
PUT (0,0),ast% 'redraw initial asterix - note XOR is default so it is erased
END SUB
'------------------------------------------------------------------------------
' draw menu bar; checkmark by specified method
'------------------------------------------------------------------------------
SUB draw.menu (method$) STATIC
'use default File and Edit menus
MENU 3,0,1,"Draw method"
MENU 3,1,1,"Primitives"
MENU 3,2,1,"Segment"
MENU 3,3,1,"Bitmap"
IF method$ = "Primitives" THEN
MENU 3,1,2
ELSEIF method$ = "Segment" THEN
MENU 3,2,2
ELSE
MENU 3,3,2
END IF
END SUB
'------------------------------------------------------------------------------
' draw an asterix at the location specified
' Note we are using Toolbox equivalents of CIRCLE and LINE, so they will
' work correctly with PENMODE statements.
'------------------------------------------------------------------------------
SUB asterix (x%,y%) STATIC
'for compiler only:
' dim angle,rect%(4)
' Important! VARPTR gets the pointer (machine address) to a variable, for use by
' certain Toolbox routines. If you misuse it you are likely to crash the computer!
setrect rect%(0),x%-radius%,y%-radius%,x%+radius%,y%+radius%
FRAMEOVAL VARPTR(rect%(0))
FOR angle = .01 TO 2*pi STEP pi/points%
MOVETO x%,y%
LINETO x%+radius%*COS(angle),y%+radius%*SIN(angle)
NEXT
END SUB
'------------------------------------------------------------------------------
' handle selection from method menu
'------------------------------------------------------------------------------
SUB handle.method.menu (item.no%,method$) STATIC
SELECT CASE item.no%
CASE 1: method$ = "Primitives"
CASE 2: method$ = "Segment"
CASE 3: method$ = "Bitmap"
CASE ELSE:
END SELECT
draw.menu method$
END SUB
'------------------------------------------------------------------------------
' handle mouse event
'------------------------------------------------------------------------------
SUB handle.mouse.down (method$,a.x%,a.y%) STATIC
'for compiler only:
' dim m.x%,m.y%,m.x.old%,m.y.old%
m.x% = MOUSE(3) 'where mouse button was first pressed - x
m.y% = MOUSE(4) 'where mouse button was first pressed - y
IF FNdistance%(a.x%,a.y%,m.x%,m.y%) < radius% THEN 'in asterix
PENMODE 10 'change pen mode to XOR for "Primitives" method
m.x.old% = m.x%
m.y.old% = m.y%
'local event loop, since other events can't occur while "dragging" icon
WHILE MOUSE(0) = -1 'while mouse still down
m.x% = MOUSE(1)
m.y% = MOUSE(2)
IF FNdistance%(m.x%,m.y%,m.x.old%,m.y.old%) > 0 THEN
SELECT CASE method$
CASE "Primitives": asterix a.x%,a.y%
a.x% = a.x%+m.x%-m.x.old%
a.y% = a.y%+m.y%-m.y.old%
asterix a.x%,a.y%
CASE "Segment": PICTURE (a.x%-radius%,a.y%-radius%),ast$
a.x% = a.x%+m.x%-m.x.old%
a.y% = a.y%+m.y%-m.y.old%
PICTURE (a.x%-radius%,a.y%-radius%),ast$
CASE "Bitmap": PUT (a.x%-radius%,a.y%-radius%),ast%
a.x% = a.x%+m.x%-m.x.old%
a.y% = a.y%+m.y%-m.y.old%
PUT (a.x%-radius%,a.y%-radius%),ast%
END SELECT
m.x.old% = m.x%
m.y.old% = m.y%
END IF
WEND
PENMODE 8 'reset penmode to COPY
END IF
END SUB